package cn.xiaoliu.basic.controller;

import cn.xiaoliu.basic.exception.BusinessException;
import cn.xiaoliu.basic.service.IVerifyCodeService;
import cn.xiaoliu.basic.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 发送验证码的接口
 */
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /**
     * param里面有两个值，一个phone一个type
     * @param param
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> param){
        try {
            iVerifyCodeService.sendSmsCode(param);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me()
                    .setSuccess(false)
                    .setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me()
                    .setSuccess(false)
                    .setMessage("业务繁忙，稍后重试");
        }
    }
}
